<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<link rel="stylesheet" href="./1.css">

<body>
  <div id="app"></div>
  <template id="my-app">
    <!-- 输入框 -->
    <header class="header">
      <h1>我的记事本</h1>
      <input placeholder="请输入任务" class="new-todo" @keyup.enter="change" />
    </header>
    <!-- 列表区域 -->
    <section class="main">
      <ul class="todo-list">
        <li class="todo" v-for="(item,index) in list" :key="item">
          <div class="view">
            <span class="index">{{index+1}}</span>
            <label>{{item}}</label>
            <button class="destroy" @click="list.splice(index,1)"></button>
          </div>
        </li>
      </ul>
    </section>
    <!-- 统计和清空 -->
    <footer class="footer" v-show="list.length>0">
      <span class="todo-count">
        <strong>{{list.length}}</strong> 项目
      </span>
      <button class="clear-completed" @click="list.length=0">
        Clear
      </button>
    </footer>
  </template>
  <script src="../lib/js/vue.js"></script>
  <script>
    const app = Vue.createApp({
      template: '#my-app',
      data: function () {
        return {
          list: ["写代码", "吃饭", "睡觉"]
        }
      },
      methods: {
        change(e) {
          this.list.push(e.target.value)
          e.target.value = ""
        }
      }
    })
    app.mount('#app')
  </script>
</body>

</html>